<template>
  <div class="text-item">{{view ? content : data.config.content}}</div>
</template>

<script>
import { getSourceData } from '../common'
export default {
  props: ['data', 'file', 'view'],
  data () {
    return {
      content: ''
    };
  },
  watch: {
    'file.extend' () {
      this.dataHandle()
    }
  },
  methods: {
    // 数据处理
    dataHandle () {
      if (this.file) {
        let { databinding } = this.data;
        let { extend } = this.file;
        if (databinding && extend) {
          try {
            let value = getSourceData(extend, databinding);
            this.content = value;
          } catch (e) {
            console.log(e);
            this.$Message.error('数据获取出错');
          }
        }
      }
    }
  },
  created () {
    this.dataHandle();
  }
};
</script>
